package com.vc.aha_server_event.controller;

import com.vc.aha_server_event.annotation.RequestLimit;
import com.vc.aha_server_event.dto.TravelThroughPageDTO;
import com.vc.aha_server_event.dto.UploadResourceInfoDto;
import com.vc.aha_server_event.entity.Event;
import com.vc.aha_server_event.entity.EventRecord;
import com.vc.aha_server_event.entity.SearchPreferences;
import com.vc.aha_server_event.service.*;
import com.vc.aha_server_event.vo.ResponseBean;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/eventTrigger")
public class EventTriggerController {
    @Resource
    private PageTrackingService pageTrackingService;
    @Resource
    private UploadResourceInfoService uploadResourceInfoService;
    @Resource
    private TravelThroughProjectNumService travelThroughProjectNumService;
    @Resource
    private SearchPreferencesService searchPreferencesService;
    @Resource
    private EventService eventService;

    @RequestLimit
    @PostMapping("/travelThroughProjectNum")
    public void saveTravelThroughProjectNum(@RequestParam Integer eventId,
                                            @RequestParam String timeStamp,
                                            @RequestParam Integer userId,
                                            @RequestParam Integer projectId
    ) {

        travelThroughProjectNumService.saveTravelProjectNum(eventId, timeStamp, userId, projectId);

    }

    @RequestLimit
    @PostMapping("/searchPreferences")
    public ResponseBean<Object> saveSearchPreferences(@RequestParam Integer eventId,
                                              @RequestParam String timeStamp,
                                              @RequestBody SearchPreferences searchPreferences
    ) {

        searchPreferencesService.saveSearchPreferences(eventId, timeStamp, searchPreferences);
        return new ResponseBean<>(null);

    }

    @RequestLimit
    @PostMapping("/travelThroughPageInfo")
    public void saveTravelThroughPageInfo(@RequestBody TravelThroughPageDTO travelThroughPageDTO) {
        pageTrackingService.savePageTrackInfo(travelThroughPageDTO);
    }

    @RequestLimit
    @PostMapping("/uploadResourceInfo")
    public void saveResourceInfo(@RequestBody @Validated UploadResourceInfoDto uploadResourceInfoDto) {
        uploadResourceInfoService.saveUploadResourceInfo(uploadResourceInfoDto);
    }

    @PostMapping("/eventStore")
    public ResponseBean<Object> eventStore(@RequestBody EventRecord eventRecord) {
        eventService.insertEventRecord(eventRecord);
        return new ResponseBean<>(null);
    }
}
